
    <div class="content margin_top">
        <header class="header fixed_top bg_mx_green"></header>
        <form class="user"></form>
    </div>
    <!-- toast模版 -->
    <script type="text/template" charset="utf-8" id='toast_template'>
        <i class="iconfont icon-toast{{=it.icon}}"></i>
        <div class="toast_text">{{=it.text}}</div>
    </script>
    <script type="text/template" charset="utf-8" id='info_template'>
        <div class="bg_white">
            <div class="padding_15 flex border_b">
                <div class="width_100">姓名</div>
                <div class="left_100">
                    <input type="text" name="name" value="{{=it.name||''}}" placeholder="请填入姓名" request title="姓名">
                </div>
            </div>
            <div class="padding_15 flex border_b">
                <div class="width_100">性别</div>
                <div class="left_100">
                    <select name="gender" id="gender">
                        <option value="男" {{if(it.gender=='男'){}}selected{{}}}>男</option>
                        <option value="女" {{if(it.gender=='女'){}}selected{{}}}>女</option>
                    </select>
                </div>
            </div>
            <div class="padding_15 flex border_b">
                <div class="width_100">简介</div>
                <div class="left_100">
                    <textarea name="descripation" placeholder="请填入简介" request title="简介">{{=it.descripation||''}}</textarea>
                </div>
            </div>

            <div class="padding_15 flex border_b">
                <div class="width_100">图形验证码</div>
                <div class="left_200">
                    <input type="text" name="pcode" value="" placeholder="请填入图形验证码" request title="图形验证码" >
                </div>
                <div class="width_100 border_l text_center"><img style="height: 30px;" id="imgVerifyCode" onclick="changeVerifyCode()"  alt="验证码"></div>
            </div>
            <div class="padding_15 flex border_b">
                <div class="width_100">手机号</div>
                <div class="left_200">
                    <input type="text" name="tel" value="{{=it.tel||''}}" placeholder="请填入手机号" request title="手机号" data-pattern="^(0|86|17951)?(13\d|15[0-35-9]|17[678]|18\d|14[57])\d{8}$" data-tips="11位手机号">
                </div>
                <div class="width_100 border_l text_center" onclick="get_code()">发送验证码</div>
            </div>
            <div class="padding_15 flex border_b">
                <div class="width_100">验证码</div>
                <div class="left_100">
                    <input type="text" name="code" value="" placeholder="请填入验证码">
                </div>
            </div>
        </div>

        <input name="_csrf" type="hidden" id="_csrf" value="<{$app->request->csrfToken}>">
        <div class="padding_15 font_16">
            <button class="btn btn_mx_green all_width lineheight_3">保存</button>
        </div>
    </script>
    <script>
        // 页面初始化
            var info = <{$userinfo}>;console.log(info)
            var evalinfo = doT.template($("#info_template").text());
            var evalToast = doT.template($("#toast_template").text());
            loaddata(".user",evalinfo,info);
            loadheadbar("个人资料");
        // 获取验证码
            var got = false;
            function get_code(){
                var tel = $("input[name='tel']").val();
                var pcode = $("input[name='pcode']").val();
                if(got) return false;
                $.post("/business/user/sms-code",{pcode:pcode,'tel':tel,'_csrf':"<{$app->request->csrfToken}>"},function(res){
                    alert(res.msg);
                    if(res.status == 0){
                        got = true;
                    }
                },"json");
            }
        // 提交表单
            var submited = false;
            $(".user").submit(function(e){
                e.preventDefault();
                with(this){
                    for (var i = 0; i < this.length; i++) {
                        if($(this[i]).attr("request")==""){
                            if(!checkone(this[i])){
                                alert('请输入正确的'+this[i].title);
                                return false;
                            }
                        }
                    }
                    if(submited) return false;
                    var data = $(".user").serialize();
                    $.post("/business/user/post-userinfo",data,function(res){
                        alert(res.msg);
                        if(res.status == 0){
                            submited = true;
                            window.location.href = res.url
                        }
                    },"json");
                }
            })


            $(function(){                   //当页面加载的时候
                changeVerifyCode();         //刷新或者重新加载一个验证码

                //清除输入框里面的数据
                $("#clear_form").click(function(){
                    $("input").val('');
                });
            });

            //更改或者重新加载验证码
            function changeVerifyCode() {
                $.ajax({
                    url: "/business/user/captcha?refresh",
                    dataType: 'json',
                    cache: false,
                    success: function(data) {
                        $("#imgVerifyCode").attr('src', data['url']);
                    }
                });
            }
    </script>


